package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.ByDayDto;
import com.zzyl.nursing.dto.FamilyRequestDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.service.IFamilyMemberService;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author syl
 * @date 2025-05-30  member/user/login
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("老人家属的登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo =  familyMemberService.login(dto);
        return success(loginVo);
    }


    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyRequestDto dto){
        familyMemberService.add(dto);
        return success();
    }


    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult queryFamilyAll(){
        List<FamilyVo> familyVos=familyMemberService.queryFamilyAll();
        return success(familyVos);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public AjaxResult queryFamilyPage(){
        startPage();
        List<ElderVO> elderVOList=familyMemberService.queryFamilyPage();
        return AjaxResult.success(elderVOList);
    }


    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId){
        List<DeviceDataVo> deviceDataVoList=familyMemberService.queryServiceProperties(iotId);
        return AjaxResult.success(deviceDataVoList);
    }


    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(ByDayDto dto){
       List<DayVo> dayVoList=familyMemberService.queryDeviceDataListByDay(dto);
        return AjaxResult.success(dayVoList);
    }


    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(ByDayDto dto){
        List<DayVo> dayVoList=familyMemberService.queryDeviceDataListByWeek(dto);
        return AjaxResult.success(dayVoList);
    }


    @DeleteMapping("/deleteById")
    @ApiOperation("解绑家人")
    public AjaxResult deleteById(@RequestParam("id") Long id){
        familyMemberService.deleteById(id);
        return AjaxResult.success();
    }



}
